package map.Topological;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        List<List<Integer>> map = new ArrayList<>();
        int[] inDegree = new int[N];
        for (int i = 0; i < N; i++) {
            map.add(new ArrayList<>());
        }
        for (int i = 0; i < M; i++) {
            int s = scanner.nextInt();
            int t = scanner.nextInt();
            map.get(s).add(t);
            inDegree[t]++;
        }
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < N; i++) {
            if (inDegree[i] == 0){
                queue.add(i);
            }
        }
        List<Integer> result = new ArrayList<>();
        while (!queue.isEmpty()){
            int cur = queue.poll();
            result.add(cur);
            for (Integer i : map.get(cur)) {
                inDegree[i]--;
                if (inDegree[i] == 0){
                    queue.add(i);
                }
            }
        }
        if (result.size() == N){
            for (int i = 0; i < result.size(); i++) {
                System.out.print(result.get(i));
                if (i < result.size() - 1){
                    System.out.print(" ");
                }
            }
        } else {
            System.out.println(-1);
        }
    }
}
